home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Inne
/
Gry
/
Carnage_Contest
/
scripts
/
CC Original
/
weapons
/
Spear.lua
< prev
next >
Wrap
Text File
|
2010-08-31
|
5KB
|
159 lines
--------------------------------------------------------------------------------
-- Weapon Spear + Projectile Spear
-- Original Carnage Contest Weapon
-- Script by DC, August 2009, www.UnrealSoftware.de
--------------------------------------------------------------------------------
-- Setup Tables
if cc==nil then cc={} end
cc.spear={}
cc.spear.spear={}
-- Load & Prepare Ressources
cc.spear.gfx_wpn=loadgfx("weapons/spear.bmp") -- Weapon Image
setmidhandle(cc.spear.gfx_wpn)
cc.spear.sfx_attack=loadsfx("arrow_shoot.ogg") -- Attack Sound
cc.spear.sfx_impact=loadsfx("arrow_impact.ogg") -- Impact Sound
--------------------------------------------------------------------------------
-- Weapon: Spear
--------------------------------------------------------------------------------
cc.spear.id=addweapon("cc.spear","Spear",cc.spear.gfx_wpn,3) -- Add Weapon (3 uses)
cc.spear.ammo=1 -- 1 Spear
function cc.spear.draw() -- Draw
if cc.spear.ammo-weapon_shots>0 then
setblend(blend_alpha)
setalpha(1)
setcolor(255,255,255)
drawinhand(cc.spear.gfx_wpn,6,0)
end
-- HUD Crosshair
if cc.spear.ammo-weapon_shots>0 then
hudcrosshair(7,3)
end
end
function cc.spear.attack(attack) -- Attack
-- Decrement timer
if weapon_timer>0 then
weapon_timer=weapon_timer-1
end
-- Attack
if weapon_shots<cc.spear.ammo and weapon_timer<=0 and attack==1 then
-- No more weapon switching!
useweapon(0)
-- Reset Timer
weapon_timer=25
-- Attack
playsound(cc.spear.sfx_attack)
weapon_shots=weapon_shots+1
id=createprojectile(cc.spear.spear.id)
projectiles[id]={}
-- Ignore collision with current player at beginning
projectiles[id].ignore=playercurrent()
-- Set initial position of projectile
projectiles[id].x=getplayerx(0)+(7*getplayerdirection(0))-math.sin(math.rad(getplayerrotation(0)))*5.0
projectiles[id].y=getplayery(0)+3+math.cos(math.rad(getplayerrotation(0)))*5.0
-- Set speed of projectile
projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*7.0
projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*7.0
-- Initial movement
projectiles[id].x=projectiles[id].x-projectiles[id].sx*1.5
projectiles[id].y=projectiles[id].y-projectiles[id].sy*1.5
for i=1,4,1 do
if cc.spear.spear.move(id)==1 then
break
end
end
-- Effects
recoil(3)
-- End Turn
if (weapon_shots>=cc.spear.ammo) then
endturn()
end
end
end
--------------------------------------------------------------------------------
-- Projectile: Spear
--------------------------------------------------------------------------------
cc.spear.spear.id=addprojectile("cc.spear.spear") -- Add Projectile
function cc.spear.spear.draw(id) -- Draw
-- Setup draw mode
setblend(blend_alpha)
setalpha(1)
setcolor(255,255,255)
setscale(1,1)
-- Calculate projectile rotation
setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
-- Draw projectile
drawimage(cc.spear.gfx_wpn,projectiles[id].x,projectiles[id].y)
-- Draw arrow if out of Screen
outofscreenarrow(projectiles[id].x,projectiles[id].y)
end
function cc.spear.spear.update(id) -- Update
-- Wind + Gravity influence on speed
projectiles[id].sx=projectiles[id].sx+getwind()*0.1
projectiles[id].sy=projectiles[id].sy+getgravity()*1.5
-- Move
cc.spear.spear.move(id)
end
function cc.spear.spear.move(id)
rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
-- Move (in substep loop for optimal collision precision)
msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
msubx=projectiles[id].sx/msubt
msuby=projectiles[id].sy/msubt
for i=1,msubt,1 do
projectiles[id].x=projectiles[id].x+msubx
projectiles[id].y=projectiles[id].y+msuby
-- Collision
if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*13,projectiles[id].y-math.cos(math.rad(rot))*13)==1 then
if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
if playercollision()~=0 then
-- Cause Player damage
playerpush(playercollision(),projectiles[id].sx/3.0,projectiles[id].sy/3.0)
playerdamage(playercollision(),35)
blood(projectiles[id].x+math.sin(math.rad(rot))*13,projectiles[id].y-math.cos(math.rad(rot))*13)
playsound(sfx_splatter3)
elseif objectcollision()>0 then
-- Cause Object Damage
objectdamage(objectcollision(),35)
else
-- Draw spear in terrain
terrainimage(cc.spear.gfx_wpn,projectiles[id].x,projectiles[id].y,0,rot)
end
-- Effects
playsound(cc.spear.sfx_impact)
particle(p_smoke,projectiles[id].x+math.sin(math.rad(rot))*14,projectiles[id].y-math.cos(math.rad(rot))*14)
particlefadealpha(0.006)
-- Free projectile
freeprojectile(id)
return 1
end
else
projectiles[id].ignore=0
end
-- Water
if (projectiles[id].y)>getwatery()+5 then
-- Effects
particle(p_waterhit,projectiles[id].x,projectiles[id].y)
if math.random(1,2)==1 then
playsound(sfx_hitwater2)
else
playsound(sfx_hitwater3)
end
-- Free projectile
freeprojectile(id)
return 1
end
end
-- Scroll to projectile
scroll(projectiles[id].x,projectiles[id].y)
end